package com.edais.actions;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.edais.domain.User;
import com.edais.service.ErrorMessageService;
import com.edais.service.LuckDrawService;
import com.edais.service.RateRisesCouponsService;
import com.edais.service.UserService;
import com.edais.service.WxCouponActivityService;
import com.edais.util.CommonUtil;
import com.edais.util.Consts;
import com.edais.util.JsonUtil;
import com.edais.util.Message;
import com.edais.util.weixinAbout.WeixinRateUrlConfig;
import com.edais.vo.LuckDraw;

@Controller
@RequestMapping("/rateRises")

public class RateRisesAction {
	private static final Log logger = LogFactory.getLog(RateRisesAction.class);
	
	@Autowired
	private RateRisesCouponsService rateRisesCouponsService;
	
	@Autowired
	private LuckDrawService luckDrawService;
	
	@Autowired
	private WxCouponActivityService wxCouponActivityService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private ErrorMessageService errorMessageService;
	
	/**
	 * 查询我的加息券
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/myRateCoupons")
	public void getBannerList(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String currentPageStr = paramsMap.get(Consts.Page.PAGE_CURRENT_NAME);//当前页
		String pageSizeStr = paramsMap.get(Consts.Page.PAGE_SIZE_NAME);//页大小
		Integer current = 1;
		Integer pageSize = 10;//默认显示10条
		String status = paramsMap.get("status");//查询状态
		String userId = paramsMap.get("userId");//用户ID
		String mobile = paramsMap.get("mobile");
		String product = paramsMap.get("product");
		try{
			
			//userId和mobile其中一个不为空
			if (StringUtils.isBlank(userId) && StringUtils.isBlank(mobile)) {
				String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
						Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

				// 处理返回结果
				CommonUtil.responseJson(result, response);
				logger.error("user/myRateCoupons 传入userId和手机号同时为空");
				return;
			}
			
			//分页参数
			if (currentPageStr != null && !("".equals(currentPageStr))) {
				current = Integer.parseInt(currentPageStr);
			}
			if (pageSizeStr != null && !("".equals(pageSizeStr))) {
				pageSize = Integer.parseInt(pageSizeStr);
			}
			Map<String,Object> reqMap = new HashMap<String,Object>();
			reqMap.put("status", status);
			reqMap.put("userId", userId);
			reqMap.put("mobile", mobile);
			reqMap.put("rowBegin",(current-1)*pageSize);
			reqMap.put("rowEnd",pageSize);
			reqMap.put("product",product);
			reqMap.put("current",current);
			jsonMap = this.rateRisesCouponsService.queryRateRisesCouponsListByParams(reqMap);
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			logger.error("查询我的加息券异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
		
	}
	
	/**
	 * 获取加息券
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/addRateRisesCoupons")
	public void addRateRisesCoupons(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String type = paramsMap.get("type");
		String mobile = paramsMap.get("mobile");
		String userId = paramsMap.get("userId");
		String shareMobile = paramsMap.get("shareMobile");
		String mediaUid = paramsMap.get("mediaUid");
		String productId = WeixinRateUrlConfig.getValue("weixin_product_id");
		
		if (StringUtils.isBlank(type)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("user/getUserMobile 传入获取加息券类型为空");
			return;
		}
		
		//userId和mobile其中一个不为空
		if (StringUtils.isBlank(userId) && StringUtils.isBlank(mobile)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
					Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.error("user/myRateCoupons 传入userId和手机号同时为空");
			return;
		}
		
		try{
			Map<String,Object> reqMap = new HashMap<String,Object>();
			reqMap.put("userId", userId);
			reqMap.put("mobile", mobile);
			reqMap.put("type", type);
			if(StringUtils.isNotBlank(shareMobile)){
				reqMap.put("shareMobile", shareMobile);
			}
			if(StringUtils.isNotBlank(mediaUid)){
				reqMap.put("mediaUid", mediaUid);
			}
			if(StringUtils.isNotBlank(productId)){
				reqMap.put("productId", productId);
			} else {
				reqMap.put("productId", "109");
			}
			jsonMap = this.rateRisesCouponsService.addRateRisesCoupons(reqMap);
			
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("获取加息券异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
	}
	
	/**
	 * 根据途径查询当日加息券
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/getTodayRateRisesCoupons")
	public void getTodayRateRisesCoupons(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String currentPageStr = paramsMap.get(Consts.Page.PAGE_CURRENT_NAME);//当前页
		String pageSizeStr = paramsMap.get(Consts.Page.PAGE_SIZE_NAME);//页大小
		Integer current = 1;
		Integer pageSize = 10;//默认显示10条
		String getWay = paramsMap.get("getWay");//查询状态
		String userId = paramsMap.get("userId");//用户ID
		String mobile = paramsMap.get("mobile");
		String status = paramsMap.get("status");//使用状态
		String useFlag = paramsMap.get("useFlag");//使用标识
		
		try{
			//userId和mobile其中一个不为空
			if (StringUtils.isBlank(userId) && StringUtils.isBlank(mobile)) {
				String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
						Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

				// 处理返回结果
				CommonUtil.responseJson(result, response);
				logger.error("user/myRateCoupons 传入userId和手机号同时为空");
				return;
			}
			//分页参数
			if (currentPageStr != null && !("".equals(currentPageStr))) {
				current = Integer.parseInt(currentPageStr);
			}
			if (pageSizeStr != null && !("".equals(pageSizeStr))) {
				pageSize = Integer.parseInt(pageSizeStr);
			}
			Map<String,Object> reqMap = new HashMap<String,Object>();
			reqMap.put("getWay", getWay);
			reqMap.put("userId", userId);
			reqMap.put("mobile", mobile);
			reqMap.put("status", status);
			reqMap.put("useFlag", useFlag);
			reqMap.put("rowBegin",(current-1)*pageSize);
			reqMap.put("rowEnd",pageSize);
			reqMap.put("current",current);
			jsonMap = this.rateRisesCouponsService.getTodayRateRisesCouponsByGetway(reqMap);
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			logger.error("查询我的加息券异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}

	}
	
	/**
	 * 使用加息券
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/useRateRises")
	public void useRateRisesCoupons(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		
		String rateIds = paramsMap.get("rateIds");
		String orderId = paramsMap.get("orderId");
		String userId = paramsMap.get("userId");
		String productId = paramsMap.get("productId");
		
		
		if (StringUtils.isBlank(rateIds)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("user/getUserMobile 传入使用加息券ID为空");
			return;
		}
		
		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("user/getUserMobile 传入userId为空");
			return;
		}
		
		if (StringUtils.isBlank(productId)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("user/getUserMobile 传入产品Id为空");
			return;
		}
		
		try{
			//如果订单为空 则根据userId查询用户当前在投活期订单
			if(StringUtils.isBlank(orderId)){
				Long userLDOrderId = this.rateRisesCouponsService.getUserLDActiveOrderId(userId);
				if(userLDOrderId==null){
					jsonMap.put("rescode", Consts.CHECK_CODE);
					jsonMap.put("resmsg_cn","对不起，您还没有投资过铃铛宝活期，请投资后再使用活期加息券！");
					String result = CommonUtil.setResultStringCn(
							jsonMap,Consts.CHECK_CODE, "对不起，您还没有投资过铃铛宝活期，请投资后再使用活期加息券！", "对不起，您还没有投资过铃铛宝活期，请投资后再使用活期加息券！");
						// 处理返回结果
						CommonUtil.responseJson(result, response);
					return;
				}
				orderId = userLDOrderId.toString();
			}
			Map<String,Object> reqMap = new HashMap<String,Object>();
			reqMap.put("rateIds", rateIds);
			reqMap.put("orderId", orderId);
			reqMap.put("productId", productId);
			
			jsonMap =  this.rateRisesCouponsService.useRateRisesCoupons(reqMap);
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			logger.error("使用加息券异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
		
		
	}
	
	/**
	 * @Description: 抽奖
	 * @param @param request
	 * @param @param response   
	 * @return void  
	 * @throws
	 * @author chenshufeng
	 * @date 2016-8-3
	 */
	@RequestMapping(value = "/userCouponsLuckDraw")
	public void userCouponsLuckDraw(HttpServletRequest request,
			HttpServletResponse response) {
		// 解密请求参数
		try{
			Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
			int times = Integer.valueOf(paramsMap.get("times"));
			Map<String, Object> userMap = new HashMap<String, Object>();
			userMap.put("mobile", paramsMap.get("mobile"));
			userMap.put("selectType", paramsMap.get("selectType"));//查询奖项类型（1-活期2-定期）
			userMap.put("times", times);//单抽1 10连抽10
			logger.info("=======================mobile:"+paramsMap.get("mobile"));
			if (paramsMap == null || paramsMap.get("mobile") == null
					|| "".equals(paramsMap.get("mobile"))) {
				String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),Consts.ERROR_CODE, "",Message.CnDescriptionExpression.MOBILE_IS_NULL);
				// 处理返回结果
				CommonUtil.responseJson(result, response);
				return;
			}
			User user = userService.getUserByParm(userMap);
			String userId = String.valueOf(user.getId());
			if (StringUtils.isBlank(userId)) {
				String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
						Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);
				// 处理返回结果
				CommonUtil.responseJson(result, response);
				logger.info("rateRises/userCouponsLuckDraw 传入用户ID为空");
				return;
			}
			//1-是否有抽奖资格
			Map<String,String> map=luckDrawService.isLuckDraw(userId);
			if(!"00000".equals(map.get("rescode"))){
				Map<String, Object> erromMap =  errorMessageService.getErrorMessage("LUCK_DRAW_TIMES_WARN");
				erromMap.put("rescode", Consts.ERROR_CODE);
				erromMap.put("resmsg_cn", "");
				String result = JsonUtil.getJsonStringFromMap(erromMap);
				CommonUtil.responseJson(result, response);
				return ;
			}
			//2-随机抽奖奖品
			List<LuckDraw> luckDrawList=luckDrawService.getLuckDraw(userMap);
			logger.info("================用户"+userId+"抽取到的奖项为："+luckDrawList);
			//3-送奖品
			Map<String,Object> pmap = new HashMap<String, Object>();
			pmap.put("luckDrawList", luckDrawList);
			pmap.put("userId", userId);
			pmap.put("mobile", paramsMap.get("mobile"));
			pmap.put("cid", map.get("cid"));
			pmap.put("times", times);//单抽1 10连抽10
			Map<String,Object> luckMap=luckDrawService.setLuckDraw(pmap);
			if(!"00000".equals(luckMap.get("rescode"))){
				Map<String, Object> erromMap =  errorMessageService.getErrorMessage("BUSINESSE_ERROR");
				erromMap.put("rescode", Consts.ERROR_CODE);
				erromMap.put("resmsg_cn", "");
				String result = JsonUtil.getJsonStringFromMap(erromMap);
				CommonUtil.responseJson(result, response);
				return ;
			}
			luckMap.put("restLuckDrawTimes", Integer.valueOf(map.get("restLuckDrawTimes"))-times);
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(luckMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			logger.error("抽奖异常:" ,e);
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
	}
	
	/**
	 * @Description: 查询用户抽奖表信息
	 * @param @param request
	 * @param @param response   
	 * @return void  
	 * @throws
	 * @author chenshufeng
	 * @date 2016-8-3
	 */
	@RequestMapping(value = "/showCouponsLuckDraw")
	public void showCouponsLuckDraw(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		
		try{
			Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
			// 手机号码不传会导致查询所有的用户
			if (paramsMap == null || paramsMap.get("mobile") == null
					|| "".equals(paramsMap.get("mobile"))) {
				String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),Consts.ERROR_CODE, "",Message.CnDescriptionExpression.MOBILE_IS_NULL);
				// 处理返回结果
				CommonUtil.responseJson(result, response);
				return;
			}
			Map<String, Object> userMap = new HashMap<String, Object>();
			userMap.put("mobile", paramsMap.get("mobile"));
			User user = userService.getUserByParm(userMap);
			String userId = String.valueOf(user.getId());
			
			if (StringUtils.isBlank(userId)) {
				String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
					Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

				// 处理返回结果
				CommonUtil.responseJson(result, response);
				logger.info("rateRises/showCouponsLuckDraw 传入用户ID为空");
				return;
			}
			Map<String,Object> reqMap = new HashMap<String,Object>(); 
			
			reqMap.put("userId", userId);
			reqMap.put("selectType", paramsMap.get("selectType"));//查询奖项类型（1-活期2-定期）
			////////////////////////////////////////////////////////////////
			//update by chenshufeng 2016-8-2
//			jsonMap = this.rateRisesCouponsService.showCouponsLuckDraw(reqMap);
			jsonMap = luckDrawService.queryLuckDrawList(reqMap);
			////////////////////////////////////////////////////////////////
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			logger.error("查询奖项列表异常:" ,e);
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",Message.CnDescriptionExpression.BUSINESSE_ERROR);
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
	}
	
	/**
	 * 查询分享信息
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryLootShareInfo")
	public void queryLootShareInfo(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		
		String mobile = paramsMap.get("mobile");//用户ID
		
		if (StringUtils.isBlank(mobile)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00009,Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("user/getUserMobile 传入mobile为空");
			return;
		}
		
		try{
			Map<String,Object> reqMap = new HashMap<String,Object>(); 
			
			reqMap.put("mobile", mobile);
			
			jsonMap = this.rateRisesCouponsService.queryLootShareInfo(reqMap); 
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			logger.error("查询分享信息异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
		
	}
	
	@RequestMapping(value = "/queryScattered")
	public void queryScatteredByRateId(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		
		String rateId = paramsMap.get("rateId");
		String loanId = paramsMap.get("loanId");
		
		/*if (StringUtils.isBlank(rateId)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("user/getUserMobile 传入加息券ID为空");
			return;
		}*/
		
		try{
			Map<String,Object> reqMap = new HashMap<String,Object>(); 
			
			if(StringUtils.isNotBlank(rateId)){
				reqMap.put("rateId", rateId);
			}
			//判断散标ID是否为空
			if(StringUtils.isNotBlank(loanId)){
				reqMap.put("loanId", loanId);
			}
			jsonMap = this.rateRisesCouponsService.queryScatteredByRateId(reqMap);
			
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
			
		}catch (Exception e) {
			logger.error("查询分享信息异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
		
	}
	
	/**
	 * 查询加息券详情
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryRateRisesByRateId")
	public void queryRateRisesByRateId(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		
		String rateIds = paramsMap.get("rateIds");
		
		if (StringUtils.isBlank(rateIds)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("rateRises/queryRateRisesByRateId 传入加息券ID为空");
			return;
		}
		
		try{
			Map<String,Object> reqMap = new HashMap<String,Object>(); 
			
			if(StringUtils.isNotBlank(rateIds)){
				reqMap.put("rateIds", rateIds);
			}
			jsonMap = this.rateRisesCouponsService.queryRateRisesByRateId(reqMap);
			
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
			
		}catch (Exception e) {
			logger.error("查询加息券详情异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
		
	}
	
	/**
	 * 查询用户当日使用加息券利率
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryUserTodayRateRises")
	public void queryUserTodayRateRises(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		
		String userId = paramsMap.get("userId");
		
		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("rateRises/queryRateRisesByRateId 传入加息券ID为空");
			return;
		}
		
		try{
			Map<String,Object> reqMap = new HashMap<String,Object>(); 
			
			if(StringUtils.isNotBlank(userId)){
				reqMap.put("userId", userId);
			}
			jsonMap = this.rateRisesCouponsService.queryUserTodayRateRises(reqMap);
			
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
			
		}catch (Exception e) {
			logger.error("查询用户当日使用加息券利率异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
		
	}
	
	/**
	 * 查询加息券分享信息
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/checkShareRateRises")
	public void checkShareRateRises(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String type = paramsMap.get("type");
		String mobile = paramsMap.get("mobile");
		String userId = paramsMap.get("userId");
		String shareMobile = paramsMap.get("shareMobile");
		String mediaUid = paramsMap.get("mediaUid");
		String productId = WeixinRateUrlConfig.getValue("weixin_product_id");
		
		if (StringUtils.isBlank(type)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("rateRisesAction/checkShareRateRises 传入获取加息券类型为空");
			return;
		}
		
		//userId和mobile其中一个不为空
		if (StringUtils.isBlank(userId) && StringUtils.isBlank(mobile)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
					Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.error("user/myRateCoupons 传入userId和手机号同时为空");
			return;
		}
		try{
			Map<String,Object> reqMap = new HashMap<String,Object>();
			reqMap.put("userId", userId);
			reqMap.put("mobile", mobile);
			reqMap.put("type", type);
			if(StringUtils.isNotBlank(shareMobile)){
				reqMap.put("shareMobile", shareMobile);
			}
			if(StringUtils.isNotBlank(mediaUid)){
				reqMap.put("mediaUid", mediaUid);
			}
			if(StringUtils.isNotBlank(productId)){
				reqMap.put("productId", productId);
			} else {
				reqMap.put("productId", "109");
			}
			jsonMap = this.rateRisesCouponsService.checkShareRateRises(reqMap);
			
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("查询加息券check异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
	}
	
	/**
	 * 查询用户当日签到信息
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/getTodayUserSignInfo")
	public void getTodayUserSignInfo(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String userId = paramsMap.get("userId");
		
		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("rateRises/getTodayUserSignInfo 传入用户ID为空");
			return;
		}
		
		try{
			Map<String,Object> requestMap = new HashMap<String,Object>();
			requestMap.put("userId",userId);
			
			jsonMap = this.rateRisesCouponsService.getTodayUserSignInfo(requestMap);
			
			String result = CommonUtil.setResultStringCn(
					jsonMap,Consts.SUCCESS_CODE, Consts.SUCCESS_DESCRIBE,"");
				// 处理返回结果
			CommonUtil.responseJson(result, response);
			
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("查询用户当日签到信息异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
	}
	
	/**
	 * 活动期疯抢加息券-库存量查询
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryWxCouponInfoByActivity")
	public void queryWxCouponInfoByActivity(HttpServletRequest request,
			HttpServletResponse response) {
		try{
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			// 处理返回结果
			jsonMap = this.wxCouponActivityService.queryWxCouponInfoByActivity();
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("查询加息券库存数量异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
	}
	
	/**
	 * 活动期疯抢加息券
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/gainWxCouponByActivity")
	public void gainWxCouponByActivity(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		// 获取用户ID
		Map<String, Object> userMap = new HashMap<String, Object>();
		userMap.put("mobile", paramsMap.get("mobile"));
		try{
			User user = userService.getUserByParm(userMap);
			String userId = String.valueOf(user.getId());
			
			if (StringUtils.isBlank(userId)) {
				// 处理返回结果
				String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
						Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);
				CommonUtil.responseJson(result, response);
				logger.debug("rateRises/gainWxCouponByActivity 传入用户ID为空");
				return;
			}
		
 			jsonMap = this.wxCouponActivityService.gainWxCouponForUser(Integer.parseInt(userId));
 			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
			return;
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("获取加息券异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
	}
}
